package com.dqyt.khjc.controller;
import com.dqyt.khjc.bean.ResultMsg;
import com.dqyt.khjc.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * 客户信息控制类
 */
@RestController
public class CustomerController {

    @Autowired
    private CustomerService customerService;

    /**
     * 查询所有未删除的客户信息
     * 在待审核申请页面的下拉框 调用
     * @return
     */
    @RequestMapping("/api/getCustomerList")
    public ResultMsg getCustomerList(HttpServletRequest request){
        ResultMsg resultMsg =customerService.getCustomerList(request);
        return resultMsg;
    }



    /**
     * 查询所有未删除的客户信息
     * 在新增客户人员信息下拉框 调用
     * @return
     */
    @RequestMapping("/api/getXzkhrylCustomerList")
    public ResultMsg getXzkhrylCustomerList(HttpServletRequest request){
        ResultMsg resultMsg =customerService.getXzkhrylCustomerList(request);
        return resultMsg;
    }



    /**
     * 查询所有未删除的客户信息  一級單位
     * 在新增客户人员信息下拉框 调用
     * @return
     */
    @RequestMapping("/api/getXzkhrylCustomerListPar")
    public ResultMsg getXzkhrylCustomerListPar(HttpServletRequest request){
        ResultMsg resultMsg =customerService.getXzkhrylCustomerListPar(request);
        return resultMsg;
    }



    /**
     * 查询所有未删除的客户信息  查询某个一级单位的下属单位
     * 在新增客户人员信息下拉框 调用
     * @return
     */
    @RequestMapping("/api/getXzkhrylCustomerListCha")
    public ResultMsg getXzkhrylCustomerListCha(HttpServletRequest request,Integer pId){
        ResultMsg resultMsg =customerService.getXzkhrylCustomerListCha(request,pId);
        return resultMsg;
    }



    /**
     * 查询所有未删除的客户信息
     * 在客户人员信息一览 调用
     * @return
     */
    @RequestMapping("/api/getKhxxylCustomerList")
    public ResultMsg getKhxxylCustomerList(HttpServletRequest request){
        ResultMsg resultMsg =customerService.getKhxxylCustomerList(request);
        return resultMsg;
    }



    /**
     * 查询所有未删除的客户信息
     * 样品管理 样品登记 调用
     * 样品管理 样品一栏 调用
     * @return
     */
    @RequestMapping("/api/getypglCustomerList")
    public ResultMsg getypglCustomerList(HttpServletRequest request){
        ResultMsg resultMsg =customerService.getypglCustomerList(request);
        return resultMsg;
    }






    /**
     *
     * @param enterpriseName 客户名称
     * @param province 省
     * @param city  市
     * @param block 区
     * @param address 地址
     * @param contacts 联系人
     * @param phone  联系人手机
     * @param email  电子邮箱
     * @param telephone 座机
     * @param fax  传真
     * @return
     */
    @RequestMapping("/api/addCustomer")
    public ResultMsg addCustomer(HttpServletRequest request,String enterpriseName,int province,int city,int block,
                                String address,String contacts,String phone,String email,String telephone,String fax){
        ResultMsg resultMsg = customerService.addCustomer(request,enterpriseName,province,city,block,address,contacts,phone,email,telephone,fax);
        return  resultMsg;
    }




    /**
     * 添加二级单位
     * @param enterpriseName 客户名称
     * @param province 省
     * @param city  市
     * @param block 区
     * @param address 地址
     * @param contacts 联系人
     * @param phone  联系人手机
     * @param email  电子邮箱
     * @param telephone 座机
     * @param fax  传真
     * @return
     */
    @RequestMapping("/api/addCustomerCh")
    public ResultMsg addCustomerCh(HttpServletRequest request,int pid,String pName,String enterpriseName,int province,int city,int block,
                                 String address,String contacts,String phone,String email,String telephone,String fax){
        ResultMsg resultMsg = customerService.addCustomerCh(request,pid,pName,enterpriseName,province,city,block,address,contacts,phone,email,telephone,fax);
        return  resultMsg;
    }



    /**
     * 修改
     * @param enterpriseName 客户名称
     * @param province 省
     * @param city  市
     * @param block 区
     * @param address 地址
     * @param contacts 联系人
     * @param phone  联系人手机
     * @param email  电子邮箱
     * @param telephone 座机
     * @param fax  传真
     * @return
     */
    @RequestMapping(value = "/api/updateCustomer", method = {RequestMethod.POST})
    public ResultMsg UpdateCustomer(HttpServletRequest request,int customerId,String enterpriseName,int province,int city,int block,
                                 String address,String contacts,String phone,String email,String telephone,String fax){
        ResultMsg resultMsg = customerService.updateCustomer(request,customerId,enterpriseName,province,city,block,address,contacts,phone,email,telephone,fax);
        return  resultMsg;
    }




    /**
     * 分页查询 客户信息
     * @param page
     * @param size
     * @param enterpriseName  客户名称
     * @param contacts     联系人
     * @param loginStatue  限制登陆状态
     * @param province 省
     * @param city  市
     * @param block  区
     * @param address  详细地址
     * @return
     */
    @RequestMapping(value = "/api/getCuListPage", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg getCustomerListPage(HttpServletRequest request,
                                         @RequestParam(defaultValue = "1") Integer page,
                                         @RequestParam(defaultValue = "10") Integer size,
                                         @RequestParam(name = "enterpriseName", required = false, defaultValue = "") String enterpriseName,
                                         @RequestParam(name = "contacts", required = false, defaultValue = "") String contacts,
                                         @RequestParam(name = "loginStatue", required = false, defaultValue = "-99") String loginStatue,
                                         @RequestParam(name = "province", required = false, defaultValue = "0") Integer province,
                                         @RequestParam(name = "city", required = false, defaultValue = "0") Integer city,
                                         @RequestParam(name = "block", required = false, defaultValue = "0") Integer block,
                                         @RequestParam(name = "address", required = false, defaultValue = "") String address
    ){
        ResultMsg resultMsg = customerService.getCustomerListPage(request,page,size,enterpriseName,contacts,loginStatue,province,city,block,address);
        return resultMsg;
    }

    /**
     * 登陆限制 客户信息
     * @param customerId
     * @param loginStatue   1:允许登陆    0禁止登陆
     * @return
     */
    @RequestMapping(value = "/api/loginRestrictions", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg loginRestrictions(HttpServletRequest request,int customerId,int loginStatue,String enterpriseName){
        ResultMsg resultMsg = customerService.loginRestrictions(request,customerId,loginStatue,enterpriseName);
        return resultMsg;
    }


    /**
     * 删除客户信息
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/api/deleteCustomer", method = {RequestMethod.GET,RequestMethod.POST})
    public ResultMsg deleteCustomer(HttpServletRequest request,int customerId,String enterpriseName){
        ResultMsg resultMsg = customerService.deleteCustomer(request,customerId, enterpriseName);
        return resultMsg;
    }



}
